package com.icarcom.cn.util.printUtil;

import java.io.File;
import java.io.FileWriter;

public class PowerUtil {


    private static String PSAM_POWER_PATH="/proc/gpiocontrol/set_id"; // uhf \sam
    private static String SCAN_WAKE_PATH="/proc/gpiocontrol/set_sam";

    private static String LOAR_MODE="/proc/gpiocontrol/set_reset";
    private static String LOAR_UHF="/proc/gpiocontrol/set_uhf";

    public static boolean power(int state) {
        if (state == 0 || state == 1) {
            try {
                FileWriter localFileWriterOn=new FileWriter (new File (PSAM_POWER_PATH));
                if (state == 1) {
                    localFileWriterOn.write ("1");
                } else if (state == 0) {
                    localFileWriterOn.write ("0");
                }
                localFileWriterOn.close ();
                return true;
            } catch (Exception e) {
                e.printStackTrace ();
                return false;
            }
        }
        return false;
    }

    public static boolean power_psam(int state) {
        if (state == 0 || state == 1) {
            try {
                FileWriter localFileWriterOn=new FileWriter (new File (SCAN_WAKE_PATH));
                if (state == 1) {
                    localFileWriterOn.write ("1");
                } else if (state == 0) {
                    localFileWriterOn.write ("0");
                }
                localFileWriterOn.close ();
                return true;
            } catch (Exception e) {
                e.printStackTrace ();
                return false;
            }
        }
        return false;
    }

    public static boolean power_reset(int state) {
        if (state == 0 || state == 1) {
            try {
                FileWriter localFileWriterOn=new FileWriter (new File (LOAR_MODE));
                if (state == 1) {
                    localFileWriterOn.write ("1");
                } else if (state == 0) {
                    localFileWriterOn.write ("0");
                }
                localFileWriterOn.close ();
                return true;
            } catch (Exception e) {
                e.printStackTrace ();
                return false;
            }
        }
        return false;
    }

    public static boolean power_uhf(int state) {
        if (state == 0 || state == 1) {
            try {
                FileWriter localFileWriterOn=new FileWriter (new File (LOAR_UHF));
                if (state == 1) {
                    localFileWriterOn.write ("1");
                } else if (state == 0) {
                    localFileWriterOn.write ("0");
                }
                localFileWriterOn.close ();
                return true;
            } catch (Exception e) {
                e.printStackTrace ();
                return false;
            }
        }
        return false;
    }

}
